/**
 * @description 格式化时间
 * @param {string} 格式
 * @param {date} 需要操作的时间
 * @returns {string} 
 */
export const formatDate = function(formatstr, date) {
	if (!date) date = new Date()
	let arrweek = ["日", "一", "二", "三", "四", "五", "六"];
	let str = formatstr.replace(/yyyy|YYYY/, date.getFullYear()).replace(/yy|YY/,
		$addZero(date.getFullYear() % 100, 2)).replace(/mm|MM/, $addZero(date.getMonth() + 1,
		2)).replace(/m|M/g, date.getMonth() + 1).replace(/dd|DD/, $addZero(date.getDate(), 2)).replace(/d|D/g,
		date.getDate()).replace(/hh|HH/, $addZero(date.getHours(), 2)).replace(/h|H/g,
		date.getHours()).replace(/ii|II/, $addZero(date.getMinutes(), 2)).replace(/i|I/g,
		date.getMinutes()).replace(/ss|SS/, $addZero(date.getSeconds(), 2)).replace(/s|S/g,
		date.getSeconds()).replace(/w|g/, $addZero(date.getDay(), 2)).replace(/W/g, arrweek[date.getDay()]);
	return str;
}

function $addZero(v, size) {
	for (let i = 0, len = size - (v + "").length; i < len; i++) {
		v = "0" + v;
	}
	return v + ""
}